<html>
<head>
<link rel='stylesheet' href='../../js/sh/SyntaxHighlighter.css' type='text/css' />
<script src='../../js/sh/shCore.js'></script>
<script src='../../js/sh/shBrushJava.js'></script>
<style>
* {
font-family:Courier New,monospace;
  padding: 0;
  margin: 0;
  white-space: nowrap;
  font-size: 11px;
}
.dp-highlighter {
  white-space: nowrap;
  overflow: visible;
  width: 600px;
  font-size: 11px;
  font-family:Courier New,monospace;
}
</style>
</head>
<body>
<textarea name='code' class='java:nogutter' rows='15' cols='120'>
/*
 * SmartGWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * SmartGWT is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation.  SmartGWT is also
 * available under typical commercial license terms - see
 * http://smartclient.com/license
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 */

import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuButton;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.menu.events.ItemClickEvent;
import com.smartgwt.client.widgets.menu.events.ItemClickHandler;
import com.smartgwt.sample.showcase.client.data.SupplyCategoryXmlDS;

public class MenuTreeBindingSample implements EntryPoint {

    public void onModuleLoad() {

		Canvas main = new Canvas();

		Menu mDepartment = new Menu();
		mDepartment.setCanSelectParentItems(true);
		mDepartment.setData(getLocalItemsAsArray());
		mDepartment.setWidth(130);

		mDepartment.addItemClickHandler(new ItemClickHandler() {
			public void onItemClick(ItemClickEvent event) {
				SC.say("You picked the \"" + event.getItem().getTitle()
						+ "\" department.");
			}
		});

		MenuButton bDepartment = new MenuButton("Go to department", mDepartment);
		bDepartment.setWidth(130);

		main.addChild(bDepartment);

		Menu mCategory = new Menu();
		mCategory.setCanSelectParentItems(true);
		mCategory.setDataSource(SupplyCategoryXmlDS.getInstance());
		mCategory.setWidth(130);

		mCategory.addItemClickHandler(new ItemClickHandler() {
			public void onItemClick(ItemClickEvent event) {
				MenuItem item = event.getItem();
				SC.say("You picked the \""
						+ item.getAttributeAsString("categoryName")
						+ "\" category.");
			}
		});

		MenuButton bCategory = new MenuButton("Go to category", mCategory);
		bCategory.setTop(30);
		bCategory.setWidth(140);

		main.addChild(bCategory);

		main.draw();
	}

	private MenuItem[] getLocalItemsAsArray() {

		MenuItem[] m = new MenuItem[4];

		m[0] = new MenuItem("Marketing");
		Menu menuMarketing = new Menu();
		menuMarketing.setData(new MenuItem("Advertising"), new MenuItem("Community Relations"));
		m[0].setSubmenu(menuMarketing);

		m[1] = new MenuItem("Sales");
		Menu menuSales = new Menu();
		menuSales.setData(new MenuItem("Direct Sales"),new MenuItem("Channel Sales"));
		m[1].setSubmenu(menuSales);

		m[2] = new MenuItem("Manufacturing");
		Menu menuManufacturing = new Menu();
		menuManufacturing.setData(new MenuItem("Design"), new MenuItem("Development"), new MenuItem("QA"));
		m[2].setSubmenu(menuManufacturing);

		m[3] = new MenuItem("Services");
		Menu menuServices = new Menu();
		menuServices.setData(new MenuItem("Support"), new MenuItem("Consulting"));
		m[3].setSubmenu(menuServices);

		return m;
	}

}
</textarea>
<script class='javascript'>
dp.SyntaxHighlighter.HighlightAll("code");
</script>
</body>
</html>
